--*******************--
--*Utility Functions*--
--*******************--

function switch(t)
	t.act = function (self,x, p, com)
		local f=self[x] or self.default
		if f then
			if type(f)=="function" then
				f(p, x, com)
			else
				error("case "..tostring(x).." not a function")
			end
		end
	end
  	return t
end

function toTable(t)
	local cmd = {}
	for word in string.gmatch(t, "%w+") do
		table.insert(cmd, word)
	end
	return cmd
end

function initArray(i, m, array)
     if (array == nil) then array = {} end
     if (m == nil) then m = i; i = 1 end
     for i = i , m do
          if (array[i] == nil) then
               array[i] = 0
          end
     end
     return array
end

function tableToString(t, n)
	local s = ""
	if (n == nil) then n = 1 end
	while (n <= #t) do
		s = s .. t[n] .. " "
		n = n + 1
	end
	return s
end

